﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;

namespace LookUpLater
{
    /// <summary>
    /// Lookup
    /// </summary>
    public class Lookup
    {
        public string Name { get; set; }
        public string Link { get; set; }
        public DateTime AddedOn { get; set; }
        public string LookupId { get; private set; }
        public string Description { get; set; }
        public LookUpStatus LookupStatus { get; set; }
        public Lookup(string name, string link, string description,string id)
        {
            this.Name = name;
            this.Link = link;
            this.Description = description;
            this.AddedOn = DateTime.Now;
            this.LookupId = id;
        }
        public Lookup(XElement element)
        {
            this.Name = element.Attribute("name").Value;
            this.Link = element.Attribute("link").Value;
            this.AddedOn = DateTime.Parse(element.Attribute("addedon").Value);
            this.LookupId = element.Attribute("lookupId").Value;
            this.LookupStatus = LookUpStatus.GetStatusById(this.LookupId);
            this.Description = element.Value;
        }

        public XElement ToXml()
        {
            return new XElement("Lookup", this.Description,
                new XAttribute("name", this.Name),
                new XAttribute("link", this.Link),
                new XAttribute("addedon", this.AddedOn.ToString("dd/MM/yyyy HH:mm:ss")),
                new XAttribute("lookupId", this.LookupId));
        }
    }
}
